package com.cskaoyan.controller;

import com.cskaoyan.bean.bo.AdminIssueCreateBo;
import com.cskaoyan.bean.bo.AdminIssueDeletBo;
import com.cskaoyan.bean.bo.AdminIssueListBo;
import com.cskaoyan.bean.bo.AdminIssueUpdateBo;
import com.cskaoyan.bean.vo.AdminOrderShipVo;
import com.cskaoyan.bean.vo.admin_issue_create.AdminIssueCreateVo;
import com.cskaoyan.bean.vo.admin_issue_list.AdminIssueListVo;
import com.cskaoyan.bean.vo.admin_issue_update.AdminIssueUpdateVo;
import com.cskaoyan.service.AdminIssueService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;

/**
 * @author Trellis
 * @since 2022/09/07 15:25
 */
@RestController
@RequestMapping("admin/issue")
public class AdminIssueController {


    @Autowired
    AdminIssueService adminIssueService;

    /**
     * 1、获取请求参数 get方法
     * 2、执行业务逻辑 根据所给的限制查找数据
     * 3、返回响应信息 json
     *
     * @param listBo
     * @return com.cskaoyan.bean.vo.admin_issue_list.AdminIssueListVo
     * @author Trellis
     * @since 2022/09/07 15:37
     */
    @RequestMapping("list")
    public AdminIssueListVo list(AdminIssueListBo listBo) {
        AdminIssueListVo listByBo = adminIssueService.getListByBo(listBo);
        return listByBo;
    }

    /**
     * 1、获取请求参数
     * 2、根据请求参数 更新数据库中的信息
     * 3、返回响应信息
     *
     * @param updateBo
     * @return com.cskaoyan.bean.vo.admin_issue_update.AdminIssueUpdateVo
     * @author Trellis
     * @since 2022/09/07 17:18
     */
    @RequestMapping("update")
    public AdminIssueUpdateVo update(@RequestBody AdminIssueUpdateBo updateBo) {
        AdminIssueUpdateVo adminIssueUpdateVo = adminIssueService.updateMessage(updateBo);
        return adminIssueUpdateVo;
    }


    /**
     * 1、获取请求参数
     * 2、根据把请求参数插入数据库同时生成时间和id
     * 3、返回携带时间和id的信息
     *
     * @param createBo
     * @return com.cskaoyan.bean.vo.admin_issue_create.AdminIssueCreateVo
     * @author Trellis
     * @since 2022/09/07 19:45
     */
    @RequestMapping("create")
    public AdminIssueCreateVo create(@RequestBody AdminIssueCreateBo createBo) throws ParseException {
        AdminIssueCreateVo message = adminIssueService.createMessage(createBo);
        return message;
    }

    /**
     *1、获取请求信息，根据获取的id进行删除
     * 2、执行业务逻辑
     * 3、返回响应信息 复用 AdminOrderShipVo代码
     * @param
     * @return
     * @author Trellis
     * @since 2022/09/07 20:03
     */
    @RequestMapping("delete")
    public AdminOrderShipVo delete(@RequestBody AdminIssueDeletBo deletBo) {
        AdminOrderShipVo orderShipVo = adminIssueService.deleteByBo(deletBo);
        return orderShipVo;
    }
}
